package learn.up.collections;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.map.CaseInsensitiveMap;
import org.junit.Test;

import learn.up.collections.Collectioins.Expression;

public class TestCollection {

	@Test
	public void tset1() {
		List<String> lsit = new ArrayList<>();
		lsit.add("23");
		lsit.add("145");
		lsit.add("534");
		boolean any = Collectioins.any(lsit, new Expression<String>() {
			@Override
			public boolean filtrate(String item) {
				return item.length() > 4;
			}

		});
		System.out.println(any);

		boolean all = Collectioins.all(lsit, (item) -> {
			return item.length() > 1;
		});
		System.out.println(all);
	}

	/**
	 * 测试map的key不分大小写
	 */
	@SuppressWarnings("unchecked")
	@Test
	public void sortedMap() {
		Map<String, Object> groupMap = new HashMap<>();
		groupMap.put("abc", 1);
		groupMap.put("Bcd", "g");
		groupMap.put("ccd", "g");
		System.out.println(groupMap.get("Abc"));
		groupMap = new CaseInsensitiveMap();
		groupMap.put("abc", 1);
		groupMap.put("Bcd", "g");
		groupMap.put("ccd", "g");
		System.out.println(groupMap.get("Abc"));
	}
	
	/**
	 * 测试帅选符合条件的元素集合返回
	 */
	@Test
	public void getElementsByCondition () {
		List<String> lsit = new ArrayList<>();
		lsit.add("23");
		lsit.add("145");
		lsit.add("534");
		lsit.add("2534");
		List<String> elementsByCondition = (List<String>) Collectioins.findConformity(lsit, (item) -> {

				return item.length() > 2;
		});
		System.out.println(elementsByCondition.size());
	}
	
}
